Back to Main Menu

Creating and Retrieving Work Request Comments

Assetic Python SDK Sample

The following code sample illustrates how to create a new supporting information comment for a work request, and get the supporting information comments for a work request.

  1. """
  2. Example script to POST a comment to supporting info of a request
  3. and then get back all comments (to illustrate GET)
  4. (Assetic.WorkRequestSupportingInfo.py)
  5. """
  6. import assetic
  7. import logging
  8. from datetime import datetime, timedelta #use to get current date
  9. ##Assetic SDK instance.
  10. asseticsdk = assetic.AsseticSDK("c:/users/kwilton/assetic.ini",None,"Info")
  11. ##work request API
  12. wrapi = assetic.WorkRequestApi()
  13. #get current datetime
  14. dt = datetime.now()
  15. wrguid = '54e43a5a-7da4-e611-946c-06edd62954d7' #set wr guid
  16. #object for POST payload
  17. info = assetic.Assetic3IntegrationRepresentationsSupportingInformation()
  18. info.description = "Comment {0}".format(str(dt))
  19. #created date can be null current date, or be set as a past date
  20. #in this example set created date to yesterday
  21. info.created_date_time = dt - timedelta(days=1)
  22. ##post the comment
  23. try:
  24. wrpost = wrapi.work_request_add_supporting_information_for_work_request(
  25. wrguid,info)
  26. except assetic.rest.ApiException as e:
  27. asseticsdk.logger.error("Status {0}, Reason: {1} {2}".format(
  28. e.status,e.reason,e.body))
  29. exit()
  30. ##get all comments for the request
  31. try:
  32. wrget = wrapi.work_request_get_supporting_information_for_work_request(
  33. wrguid)
  34. except assetic.rest.ApiException as e:
  35. asseticsdk.logger.error("Status {0}, Reason: {1} {2}".format(
  36. e.status,e.reason,e.body))
  37. exit()
  38. ##set logger format to make it easier to read
  39. formatter = logging.Formatter('%(levelname)s - %(message)s')
  40. asseticsdk.logger.handlers[0].setFormatter(formatter)
  41. ##display all comments using logger
  42. ##each comment entered in supporting information is a separate record
  43. for h in wrget["ResourceList"]:
  44. asseticsdk.logger.info(
  45. "Date: {0}, Comment: {1}, Created By: {2}".format(
  46. h.get("CreatedDateTime"),h.get("Description"),h.get("CreatedByDisplayName")))